<script>
export default {
  globalData: {
    isLoggedIn: false,
    userInfo: null
  },
  
  onLaunch: function() {
    // 初始化时检查登录状态
    const token = uni.getStorageSync('token')
    const username = uni.getStorageSync('username')
    const imgurl = uni.getStorageSync('imgurl')
    
    if (token && username && imgurl) {
      this.globalData.isLoggedIn = true
      this.globalData.userInfo = {
        token,
        username,
        imgurl
      }
    }
  },
  
  onShow: function() {
    this.checkLoginStatus();
  },
  
  methods: {
    checkLoginStatus() {
      const token = uni.getStorageSync('token');
      const username = uni.getStorageSync('username');
      const imgurl = uni.getStorageSync('imgurl');
      
      if (token && username) {
        this.globalData.isLoggedIn = true;
        this.globalData.userInfo = {
          token,
          username,
          imgurl
        };
      } else {
        this.globalData.isLoggedIn = false;
        this.globalData.userInfo = null;
      }
    }
  }
}
</script>

<style>
	/*每个页面公共css */
</style>
